<?php

/**
 * This is the model class for table "contactos".
 *
 * The followings are the available columns in table 'contactos':
 * @property integer $Id
 * @property string $Cedula
 * @property string $Telefono_Celular
 * @property string $Telefono_Fax
 * @property string $Telefono_Oficina
 * @property string $Email
 * @property string $Direccion
 *
 * The followings are the available model relations:
 * @property Cliente $cedula
 */
class Contactos extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Contactos the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'contactos';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('Cedula, Telefono_Celular, Email, Direccion', 'required'),
			array('Cedula', 'length', 'max'=>30),
			array('Telefono_Celular, Telefono_Fax, Telefono_Oficina, Email', 'length', 'max'=>50),
			array('Direccion', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('Id, Cedula, Telefono_Celular, Telefono_Fax, Telefono_Oficina, Email, Direccion', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'cedula' => array(self::BELONGS_TO, 'Cliente', 'Cedula'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'Id' => 'ID',
			'Cedula' => 'Cedula',
			'Telefono_Celular' => 'Telefono Celular',
			'Telefono_Fax' => 'Telefono Fax',
			'Telefono_Oficina' => 'Telefono Oficina',
			'Email' => 'Email',
			'Direccion' => 'Direccion',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('Id',$this->Id);
		$criteria->compare('Cedula',$this->Cedula,true);
		$criteria->compare('Telefono_Celular',$this->Telefono_Celular,true);
		$criteria->compare('Telefono_Fax',$this->Telefono_Fax,true);
		$criteria->compare('Telefono_Oficina',$this->Telefono_Oficina,true);
		$criteria->compare('Email',$this->Email,true);
		$criteria->compare('Direccion',$this->Direccion,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        /**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function searchbyId($Cedula)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		$criteria->compare('Cedula',$this->Cedula,true);
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}